<template>
  <div class="app-container">
    <!--查询条件开始-->
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="所属班级" prop="claId">
        <el-select
          v-model="queryParams.claId"
          placeholder="所属班级"
          clearable
          size="small"
          style="width:240px"
        >
          <el-option
            v-for="c in ClassOptions"
            :key="c.classId"
            :label="c.className"
            :value="c.classId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="就业老师" prop="jobTeachername">
        <el-select
          v-model="queryParams.jobTeachername"
          placeholder="就业老师"
          clearable
          size="small"
          style="width:240px"
        >
          <el-option
            v-for="dict in teacherOptions"
            :key="dict.userId"
            :label="dict.userName"
            :value="dict.userId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="就业时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width:240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholde="开始日期"
          end-placeholde="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--查询条件结束-->

    <!--表头按钮开始-->
    <!--    <el-row :gutter="10" style="margin-bottom: 8px;">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
          </el-col>
        </el-row>-->
    <!--表头按钮结束-->

    <!--数据表格开始-->
    <el-table v-loading="loading" border :data="deptTableList" >
      <el-table-column label="学生名称" align="center" prop="stuName"/>
      <el-table-column label="班级名称" align="center" prop="claName"/>
      <el-table-column label="就业老师" align="center" prop="jobTeacherName"/>
      <el-table-column label="就业时间" align="center" prop="jobTime">
        <template slot-scope="scope">
          {{ formatDateNew(scope.row.jobTime, '{y}-{m}-{d}') }}
        </template>

      </el-table-column>
      <el-table-column label="岗位" align="center" prop="jobPost"/>
      <el-table-column label="就业公司名称" align="center" prop="jobCompany"/>
      <el-table-column label="就业薪资" prop="jobSalary" align="center"/>
      <el-table-column label="联系电话" align="center" prop="iphon"/>
      <el-table-column label="备注" align="center" prop="jobRecord"/>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" size="mini" @click="handleUpdate(scope.row.id)">修改</el-button>
<!--          <el-button type="text" icon="el-icon-delete" size="mini" @click="handleDelete(scope.row)">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <!--数据表格结束-->

    <!--分页控件开始-->
    <el-pagination
      v-show="total>0"
      :current-page="queryParams.pageNum"
      :page-sizes="[5, 10, 20, 30]"
      :page-size="queryParams.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <!--分页控件结束-->

    <!-- 添加就业弹框开始 -->
    <el-dialog :title="titele = '修改就业信息'" :visible.sync="getJobOpen" append-to-body center width="650">
      <el-form :model="studentJob" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="学生姓名" prop="stuName">
              <el-input v-model="studentJob.stuName" placeholder="请输入用户名称" :disabled="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="班级" prop="claName">
              <el-input v-model="studentJob.claName" placeholder="班级名称" :disabled="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="就业老师" prop="jobId">
              <el-select v-model="studentJob.jobId" clearable placeholder="就业老师" size="small" style="width: 100%;" @change="changeJobId">
                <el-option
                  v-for="d in teacherOptions"
                  :key="d.userId"
                  :label="d.userName"
                  :value="d.userId"
                />
              </el-select>
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="就业时间" prop="jobTime">
              <el-date-picker v-model="studentJob.jobTime" placeholder="就业时间" style="width: 100%;" type="date"
                              value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="就业岗位" prop="jobPost">
              <el-input v-model="studentJob.jobPost" placeholder="就业岗位"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="就业公司名称" prop="jobCompany">
              <el-input v-model="studentJob.jobCompany" clearable placeholder="就业公司名称"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="就业薪资" prop="jobSalary">
              <el-input v-model="studentJob.jobSalary" placeholder="就业薪资"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="联系电话" prop="iphon">
              <el-input v-model="studentJob.iphon" placeholder="联系电话"/>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="备注" prop="jobRecord">
              <el-input v-model="studentJob.jobRecord" placeholder="备注" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>

      <span slot="footer" >
        <el-button type="primary" @click="addGetJob">确 定</el-button>
        <el-button @click="clearGetJobOpen">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 添加就业弹框结束 -->

  </div>
</template>
<script>
import { getClassByUserCampus } from '@/api/system/class'
import { getUserByRole } from '@/api/system/user'
import { listGitJobForPage ,updateGetJob ,getJobById} from '@/api/system/gitjob'

export default {
  data() {
    return {
      //查询条件
      queryParams: {
        deptName: undefined,
        status: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 就业老师集合
      teacherOptions: [],
      // 班级集合
      ClassOptions: [],
      //时间
      dateRange: [],
      //状态数据值集
      statusOptions: [],
      //非单个禁用
      single: true,
      //非多个禁用
      multiple: true,
      //弹出层显示
      open: false,
      //弹出层标题
      title: '',
      //遮罩
      loading: false,
      //表格数据
      deptTableList: [],
      //表单数据
      form: {},
      //选中的id
      ids: [],
      //数据数量
      total: 0,
      //修改弹框
      getJobOpen:false,
      // 就业信息
      studentJob:{},
    }
  },
  //钩子
  created() {
    getUserByRole('role:301').then(res => {
      this.teacherOptions = res.data
    })
    getClassByUserCampus().then(res => {
      this.ClassOptions = res.data
    })
    this.getDataByType('sys_normal_disable').then(res => {
      this.statusOptions = res.data
    })
    this.getListForPage()

  },
  methods: {

    // 选择就业老师触发
    changeJobId(jobTeacherId){
      Object.keys(this.jobTeacherList).map((key) => {
        if (this.jobTeacherList[key].userId == jobTeacherId) {
          this.studentJob.jobTeacherName = this.jobTeacherList[key].userName
          return false
        }
      })
    },

    // 打开修改弹框
    handleUpdate(jobId){
      getJobById(jobId).then(response => {
        console.log(response)
        this.studentJob = response.data
        this.getJobOpen = true
      })
    },

    // 确定修改
    addGetJob(){
      updateGetJob(this.studentJob).then(reponse => {
        if (reponse.data){
          this.msgSuccess('保存成功')
          this.getListForPage()
          this.clearGetJobOpen()
        }
      })
    },

    // 取消修改
    clearGetJobOpen(){
      this.getJobOpen = false
    },

    //查询表格数据
    getListForPage() {
      this.loading = true
      listGitJobForPage(this.addDateRange(this.queryParams, this.dateRange))
        .then(res => {
          //获得请求的数据
          this.deptTableList = res.data
          //获得请求的条数
          this.total = res.total
          this.loading = false
        })
    },

    //查询按钮事件
    handleQuery() {
      this.getListForPage()

    },
    //重置按钮事件
    resetQuery() {
      this.resetForm('queryForm')
      this.dateRange = []
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.getListForPage()
    },

    //当前页大小发生改变触发事件
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      this.getListForPage()
    },
    //当前页改变触发事件
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.getListForPage()
    },
  }

}
</script>
